package jgl.vajra.management.part.mine.viewModel;

import java.util.Map;

import jgl.vajra.management.bean.CarDetailsBean;
import jgl.vajra.management.part.mine.contract.CarDetailsContract;
import jgl.vajra.management.part.mine.model.CarDetailsModel;
import jgl.vajra.management.widget.mvvm.factory.CreateModel;
import jgl.vajra.management.widget.retrofithelper.rxsubscriber.ProgressObserver;
import jgl.vajra.management.widget.utils.ToastUtils;

@CreateModel(CarDetailsModel.class)
public class CarDetailsViewModel extends CarDetailsContract.ViewModel {
    @Override
    public void getCarDetailsData(Map<String, Object> map) {
        mModel.getCarDetailsData(map).subscribe(new ProgressObserver<CarDetailsBean>(true, this) {
            @Override
            public void _onNext(CarDetailsBean data) {
                mView.returnCarDetailsData(data);
            }
        });
    }

    @Override
    public void deleteCarData(Map<String, Object> map) {
        mModel.deleteCarData(map).subscribe(new ProgressObserver<Object>(true, this) {
            @Override
            public void _onNext(Object o) {
                mView.returnDeleteCarData();
            }
        });
    }

    @Override
    public void modifyCarData(Map<String, Object> map) {
        mModel.modifyCarData(map).subscribe(new ProgressObserver<String>(true, this) {
            @Override
            public void _onNext(String data) {
                ToastUtils.showShort(data);
            }

            @Override
            public void _onError(String errorMessage, int errorCode) {
                super._onError(errorMessage, errorCode);
                ToastUtils.showShort(errorMessage);
            }
        });
    }
}
